<?php
class contactActions extends myFrontendAction{

  public function preExecute()
  {
    $this->form = new SimpleContactForm();
  }

  

  public function executeSubmit(sfRequest $request)
    {
        $this->form->bind($request->getParameter($this->form->getName()));
        sfProjectConfiguration::getActive()->loadHelpers(array('I18N', 'Variable'));

        if($this->form->isValid())
        {
            $this->content = 'Parents name: '.$this->form->getValue('parent')."\n".
                    'Childs name: '.$this->form->getValue('child')."\n".
                    'Childs birthday: '.$this->form->getValue('birthday')."\n".
                    'Email: '.$this->form->getValue('email')."\n".
                    'Phone: '.$this->form->getValue('phone')."\n".
                    'Message: '.$this->form->getValue('message')."\n";
            
            $this->getMailer()->composeAndSend(variable('email'), variable('email'), 'Message sent from britanica.ee contact form',
            'Message from homepage:'."\n".
            $this->content);

            $this->renderPartial('global/json', array('item' => array(
            'code' => 200,
            'notice' => '<p class="contact-sent">'.__('email_send_success').'</p>'
            )));      
        } 
        else
        {
            $this->renderPartial('global/json', array('item' => array(
            'code' => 500,
            'errors' => $this->form->getErrors()
            )));
        }

        return sfView::NONE;
    }
}